﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Domain.Abstract;
using Ninject;
using Domain.Concrete;

namespace WebUI.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private readonly IKernel _ninjectKernel;

        public NinjectControllerFactory()
        {
            _ninjectKernel = new StandardKernel();
            AddBinding();
        }

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null : (IController)_ninjectKernel.Get(controllerType);
        }

        private void AddBinding()
        {
            _ninjectKernel.Bind<INccRepository>().To<NccRepository>();
            _ninjectKernel.Bind<IQuanHuyenRepository>().To<QuanHuyenRepository>();
            _ninjectKernel.Bind<INhomNccRepository>().To<NhomNccRepository>();
            _ninjectKernel.Bind<IXaPhuongRepository>().To<XaPhuongRepository>();
        }
    }
}